package com.ma4567.remotecontroller.InfoRequest;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.ma4567.remotecontroller.MysqlHelper.TableLogManager;
import com.ma4567.remotecontroller.MysqlHelper.TableRequestLog;
import com.ma4567.remotecontroller.RemoteControllerApplication;
import com.ma4567.remotecontroller.ffmpegManager.ffmpegController;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

import javax.naming.ldap.Control;
import java.sql.SQLException;

class getSystemControlRequest extends com.ma4567.remotecontroller.util.CustomRespone{
    public getSystemControlRequest(int Status) {
        super(Status);
    }
}

@CrossOrigin
@RestController
public class SystemControlRequest {
    @RequestMapping(value = "/api/getSystemControl", method = RequestMethod.GET)
    public String getSystemControl(HttpServletRequest request,
                                   @RequestParam("cookie") String Cookie,
                                   @RequestParam("method") String ControlMethod) throws SQLException {
        ffmpegController.StopStream();
        TableRequestLog.AddLog(ControlMethod + "system", Cookie, request.getRemoteAddr());
        if(!RemoteControllerApplication.userManager.JudgeCookie(Cookie)){//鉴权
            return JSONObject.toJSONString(new getSystemControlRequest(1), SerializerFeature.PrettyFormat);
        }
        else {
            TableLogManager.AddLog(ControlMethod + "system", Cookie);
            return JSONObject.toJSONString(new getSystemControlRequest(0), SerializerFeature.PrettyFormat);
        }
    }
}
